class Solution {//leetcode733——图像渲染
private:
    int dx[4]={0,0,-1,1};
    int dy[4]={-1,1,0,0};
    void _dfs(vector<vector<int>>& image,int i,int j){
        image[i][j]=newcolor;
        for(int k=0;k<4;k++){
            int y=i+dy[k];
            int x=j+dx[k];
            if(x>=0&&x<n&&y>=0&&y<m&&image[y][x]==dest_color){
                _dfs(image,y,x);
            }
        }
    }
public:
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        if(color!=image[sr][sc])
        {
            dest_color=image[sr][sc];
            m=image.size();
            n=image[0].size();
            newcolor=color;
            _dfs(image,sr,sc);
        }
        return image;
    }
    int newcolor;
    int m;
    int n;
    int dest_color;
};